package com.xzk.ExpressInnWeb.web.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter({"/index.html","/expressList.html",
        "/personQRcode.html","/showExpress.html","/lazyBoard.html","/wxUserhome.html",
        "/wxIdCardUserInfoModify.html","/userCheckStart.html","/wechat/identify.do",
        "/wechat/findExpressesByPhone.do","/wechat/generateQRCodeContent.do",
        "/wechat/qrcode.do","/wechat/getUserExList.do","/wechat/gofindExByExNum.do",
        "/wechat/findExByExNum.do","/wechat/getLazyBoardValues.do","/wechat/getIdentity.do","/wechat/getPhone.do"})
public class WechatFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        Object phone = req.getSession().getAttribute("phone");
        if (phone == null)
            resp.sendRedirect("/login.html");
        else
            chain.doFilter(request,response);
    }

    @Override
    public void destroy() {

    }
}
